<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="/assets/css/base.css">
  <link rel="stylesheet" href="/assets/css/iconfont.css">
  <link rel="stylesheet" href="/assets/css/public.css">
  <link rel="stylesheet" href="/assets/css/list.css">
</head>

<body>
  <div class="container">
    @@include('./assets/common/home/nav.html')

    <div class="content">

    </div>


    <div class="footer">
      <p>© 2016 XIU主题演示 本站主题由 themebetter 提供</p>
    </div>

    @@include('./assets/common/home/rightData.html')
  </div>
</body>

@@include('./assets/common/base.html')

<!-- 模板 -->
<script type="text/template" id="contentTemplate">
  <div class="item release">
    <h3>  {{result[0].category.title}}</h3>
    {{each result}}
    <div class="item-box">
      <div class="header">
        <span class="life">{{$value.category.title}}</span>
        <a href="detail.html?id={{$value._id}}" class="title">{{$value.title}}</a>
      </div>
      <div class="main">
        <p class="info">{{$value.author.nickName}} 发表于 {{handleDate($value.author.createTime)}}</p>
        <p class="dec">{{$value.content}}</p>
        <p class="extra">
          <span class="read">阅读({{$value.meta.views}})</span>
          <span class="comment">评论({{$value.meta.comments}})</span>
          <a href="javascript:;" class="zan">
            <span class="iconfont icon-dianzan icon"></span>
            赞({{$value.meta.likes}})
          </a>
          <a href="javascript:;">
            分类:
            <span>{{$value.category.title}}</span>
          </a>
        </p>
        <a href="detail.html?id={{$value._id}}" class="pic">
          <img src="{{baseUrl}}{{$value.thumbnail}}" alt="">
        </a>
      </div>
    </div>
  {{/each}}
  </div>
</script>

<script>
  $(function () {

    function formDate(dateStr) {
      let date = new Date(dateStr);
      return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
    }
    let keyUrl = window.location.search
    let keyStr = keyUrl.split('?')[1]
    let key = keyStr.split('=')[1]

    // 发送搜索的ajax请求
    $.ajax({
      url: baseUrl + '/posts/search/' + key,
      type: 'get',
      success(res) {
        const newHtml = template('contentTemplate', {
          result: res,
          baseUrl,
          handleDate: formDate
        })
        $('.content').html(newHtml)
      },
      error(err) {
        console.log(err);
      }
    })
  })
</script>

</html>